import http from '@/utils/http'
import {LoginFormType, LoginType, RegisterFormType} from '@/type/user'
import {HomeCarouselType, HomeCategoryType, productType, recommendList} from '@/type/homeType'
import {ShoppingList, ShoppingSave} from '@/type/shopping'
import {SettleShoppingListType} from '@/type/settle'
import {PersonalDataForm} from '@/type/personalData'
import {addressList} from '@/type/componentType'
import {shippingAddressList, shippingAddressSaveType} from '@/pages/shippingAddress'
import {ProductList, ProductURL} from '@/type/product'
import {orderLogisticsType, orderStatusType} from '@/type/personalDeal'
import {receivedSaveType} from '@/type/receivedType'

// 登录接口
export const login = (data:LoginFormType) => http.post<LoginType>("user/login", data)
// 注册接口
export const register = (data:RegisterFormType) => http.post("user/register", data)

// 首页轮播图
export const carousel = () => http.get<HomeCarouselType[]>("home/carousel")
// 首页分类
export const category = () => http.get<HomeCategoryType[]>("home/category")
// 首页推荐
export const recommend = () => http.get<recommendList[]>("home/recommend")

// 根据id获取商品信息
export const product = (params: {product_id: string}) => http.get<productType>("home/product", params)


// 添加购物车
export const shoppingSave = (data:ShoppingSave) => http.post("shopping/save", data)
// 购物车列表
export const shoppingList = (data = {}) => http.post<ShoppingList[]>("shopping/list", data)
// 删除购物车
export const shoppingDel = (params: {
  id: number
}) => http.del("shopping/delete", params)
// 确认订单添加
export const shoppingOrder = (data: ShoppingList[]) => http.post("shopping/order", data)

// 确认订单列表
export const affirm_orderList = () => http.get<SettleShoppingListType[]>("affirm_order/list")

// 查看个人信息
export const userQuery = () => http.get<PersonalDataForm>("user/query")
export const userUpdate = (data) => http.post("user/update",data)
export const userGetImage = () => http.get<{
  pic: string
}>("user/getImage")

export const delImage = (data: {
  pic: string
}) => http.post("user/delImage", data)

// 省市区级联接口
export const codeAddress = (params?:{
  id: number| null
}) => http.get<addressList[]>("code/address", params)

// 收货地址标签
export const codeTags = () => http.get<string[]>("code/site/tag")
// 收货地址添加
export const siteSave = (data: shippingAddressSaveType) => http.post("site/save", data)
export const siteList = () => http.get<shippingAddressList[]>("site/list")

export const siteDefault = (data:{
  id: number | string
}) => http.post("site/default", data)

export const siteDelete = (params: {
  id: number | string
}) => http.del("site/delete", params)


// 提交订单
export const orderSave = (data: {
  list: SettleShoppingListType[]
}) => http.post<string[]>("order/save", data)
// 获取总价
export const orderTotalMoney = (data: {
  ids: string
}) => http.post<{
  totalMoney: number,
  table: {name: string,money: number}[]
}>("order/totalMoney", data)

// 订单支付
export const orderPayment = (data: {
  ids: string
}) => http.post("order/payment", data)

// 订单状态
export const orderStatus = () => http.get<orderStatusType[]>("order/status")

// 代付款
export const orderObligation = () => http.get("order/obligation")
// 商品查询
export const productList = (data: ProductURL) => http.post<ProductList[]>("product/list", data)

export const productDiscount = () => http.get<ProductList[]>("product/discount")

// 物流信息
export const orderLogistics = () => http.get<orderLogisticsType[]>("order/logistics")
// 确认收货
export const orderConfirm = (data:orderLogisticsType) => http.post("order/confirm", data)

export const homeComment = (data: {
  product_id: string
}) => http.post("home/comment",data)

export const orderReceived = (data = {}) => http.post<orderLogisticsType[]>("order/received",data)
// 评价
export const orderReceivedSave = (data:receivedSaveType) => http.post("order/received/save", data)
// 退货
export const orderSales = (data:orderLogisticsType) => http.post("order/sales", data)

export const orderConfig = (data:orderLogisticsType) => http.post("product/config", data)
